<%--管理员-博客管理列表--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <meta charset="utf-8">
    <title>图形图像处理交流网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
                    <%--修改密码板块--%>
                        <form:form class="layui-form" action="" method="post">
                            <div class="layui-form-item">
                                <label for="pwd" class="layui-form-label">当前密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="pwd" required lay-verify="required|oldPwd" autocomplete="off" class="layui-input">
                                        <%--<input type="hidden" id="oldPwd" value="${pwd}">&lt;%&ndash;原始密码&ndash;%&gt;--%>
                                    <input type="hidden" name="uId" value="${user.uId}"><%--用户id--%>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="newPwd" class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="newPwd" name="uPassword" required lay-verify="required|newPwd|confirmPwd" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="confirmPwd" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="confirmPwd" name="confirmPwd" required lay-verify="required|newPwd|confirmPwd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn"  lay-filter="addForm" lay-submit>确认修改</button>
                            </div>
                        </form:form>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js" ></script>
<script src="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        version: "3.0.0"
        ,base: '${pageContext.request.contextPath}/js/'
    }).extend({
        fly: 'index'
    }).use('fly');
</script>
<!--导航栏-->
<script>
    layui.use('element', function(){
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function(elem){
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
</script>

<%--校验表单--%>
<script>
    layui.use([ 'form' ], function() {
        var form = layui.form,
            layer = layui.layer
        /* 自定义表单验证 */
        form.verify({
            //原始密码验证
            oldPwd : function(value, item){
                var message = '';
                $.ajax({
                    type:"POST",
                    url:'${pageContext.request.contextPath}/blog/student/repwd.do',
                    async: false, //改为同步请求
                    data:{"pwd":value},
                    success:function(data){
                        if(data.code==0){
                            message='';
                        }else{
                            message ="原始密码输入错误！";
                        }
                    }
                });
                //需要注意  需要将返回信息写在ajax方法外
                if (message!='') {
                    return message;
                }
            },
            newPwd : [ /^[\S]{6,16}$/, '密码必须6到16位，且不能出现空格' ],

            confirmPwd : function(value, item){
                if($("#newPwd").val()!=value){
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        });
        /*提交表单*/
        form.on('submit(addForm)', function(data){
            $.ajax({
                url:'${pageContext.request.contextPath}/admin/editPwd.do',
                method:'post',
                data:data.field,
                async: false,
                dataType:'JSON',
                success:function(res){
                    console.log(res.code);
                    switch(res.code){
                        case 200:
                            layer.msg(res.msg, function () {
                                window.location = '${pageContext.request.contextPath}/user/to_login.do';
                            });
                            break;
                        case -1:
                            layer.msg(res.msg, {icon: 2});
                            break;
                        case -2:
                            //登录失效
                            alert('登录失效');
                            window.open("${pageContext.request.contextPath}/user/to_login.do");
                            break;
                    }
                },
                error:function (data) {

                }
            }) ;

        });
    });
</script>


</body>
</html>
